﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Scripting;
using Microsoft.Linq.Expressions;
using Microsoft.Scripting.Actions;

namespace JavascriptEngine.Runtime
{
    public class JavascriptConvertBinder : ConvertBinder
    {
        public JavascriptBinder Binder { get; private set; }
        public ConversionResultKind ResultKind { get; private set; }

        public JavascriptConvertBinder(JavascriptBinder binder, Type type, ConversionResultKind resultKind)
            : base(type, resultKind == ConversionResultKind.ExplicitCast || resultKind == ConversionResultKind.ExplicitTry)
        {
            this.Binder = binder;
            this.ResultKind = ResultKind;
        }

        public override DynamicMetaObject FallbackConvert(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
        {
            return Binder.ConvertTo(Type, ResultKind, target);
        }
    }
}
